const http = require('http');
const url = require('url');

const sv = http.createServer((req, res) => {
    // console.log('访问地址：' + req.url)
    // let resGet = url.parse(req.url,true); // true 设置为对象
    // console.log('pathname:', resGet.query.keyword)
    // res.end('hello!')

    /**
     * 另一种
     *  let url01 = new URL('/search?q=100&b=200','http://localhost:3000')
     */
    // req.url 为请求头中的 url
    let url02 = new URL(req.url, 'http://localhost:3000');
    // 取到查询地址
    console.log(url02.pathname)
    // 输出 keyword 查询字符串
    console.log(url02.searchParams.get('keyword'))
    res.end('Welcome!')
});

sv.listen(3000, () => {
    console.log('Server is running at http://localhost:3000');
});

